//编写你自己版本的用shared_ptr管理connection的函数。
#include<iostream>
#include<vector>
#include<memory>
using namespace std;

struct destination {};
struct connection  {};
connection connect(destination *pd)
{
	cout << "打开连接" << endl;
	return connection();
}
void disconnection(connection c)
{
	cout << "关闭连接" << endl;
}
void f(destination &d)
{
	cout << "直接管理connect" << endl;
	connection c = connect(&d);
	//忘记调用disconnect关闭连接
	cout << endl;
}
void end_connection(connection *p) { disconnection(*p); }
//shared_ptr版本
void f1(destination &d)
{
	cout << "用shared_ptr管理connect" << endl;
	connection c = connect(&d);
	shared_ptr<connection>p(&c, end_connection);
	//忘记调用disconnect关闭连接,会调用end_connection 析构
	cout << endl;
}
int main()
{
	destination d;
	f(d);
	f1(d);
	return 0;
}